package org.bookie.mtest;


import static org.testng.Assert.assertEquals;

import java.io.IOException;
import java.net.MalformedURLException;

import org.bookie.mtest.framework.Application;
import org.bookie.mtest.framework.UserListPage;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import com.meterware.httpunit.WebTable;

@Test
public class UserListPageTest {
	public void testUserTable() throws MalformedURLException, SAXException, IOException{
		UserListPage page = createPage();
		
		WebTable table = page.getUserTable();
		assertEquals(table.getColumnCount(), 3);
		assertEquals(table.getRowCount(), 10+2);
		assertEquals(table.getCellAsText(1, 0), "Homer Simpson");
		
		//now test sort links
		page.clickOnLinkWithText("Username");
		table = page.getUserTable();
		assertEquals(table.getCellAsText(1, 0), "Abraham Simpson");
		
		page.clickOnLinkWithText("Joined");
		table = page.getUserTable();
		assertEquals(table.getCellAsText(1, 0), "Homer Simpson");
		
		page.clickOnLinkWithText("Balance");
		page.clickOnLinkWithText("Balance");
		table = page.getUserTable();
		assertEquals(table.getCellAsText(1, 0), "Marge Simpson");
	}
	
	private UserListPage createPage() throws MalformedURLException, SAXException, IOException{
		Application application = new Application();
		UserListPage page = application.start().getUserListPage();
		page.assertPageTitle("Members");
		return page;
	}
}
